<template>
    <view class="g_content content_box">
        <view class="bg"></view>
        <view class="content p_20">
            <view class="c_f f_s_20 m_t_50 m_l_10">
                <view >嗨，您 好</view>
                <view class="m_t_5">欢 迎 您 使 用 三 只 猋</view>
            </view>
            <view class="card_box p_20 p_b_20 m_t_50" style="width: 85vw">
                <view class="dis_f_c_c">
                    <u-button type="success" shape="circle"  @click="handleLogin">微信一键登录</u-button>
                </view>
                <view class="dis_f_r_c m_t_10">
                    <u-checkbox-group
                        size="16"
                        v-model="checkboxValue"
                        placement="column"
                    >
                        <u-checkbox
                            activeColor="#54B62D"
                            label=" "
                            name="agreement"
                        >
                        </u-checkbox>
                    </u-checkbox-group>
                    <view class="f_s_14 c_blue"> <text  @click="handleToProtocol(2)"> 《用户协议》</text>和 <text  @click="handleToProtocol(3)"> 《隐私协议》 </text></view>
                </view>
            </view>
        </view>
    </view>
</template>

<script>
import {loginApi} from "@/sheep/api/login";
import {bindAgentId} from '@/sheep/utils/common'

export default {
    data() {
        return {
            checkboxValue: [],
        };
    },
    methods: {
        handleToProtocol(e){
            uni.navigateTo({
                url: '/pages/agreement/index?type='+e
            })
        },
        handleLogin() {
            if (this.checkboxValue.length==0){
                uni.showToast({
                    title: '请勾选用户协议和隐私协议',
                    icon: 'none'
                })
                return
            }
                let loginBody = {
                    xcxCode: "",
                    isBindPhone: false,
                    clientId: "be7052a7e4f802c20df10a8d131adb12",
                    grantType: "xcx",
                    tenantId: "000000",
                };
                uni.login({
                    provider: "weixin",
                    success: function (loginRes) {
                        loginBody.xcxCode = loginRes.code;
                        loginApi(loginBody).then((res) => {
                            if (res.code === 200) {
                                uni.setStorageSync('token',res.data.access_token)
                                if (uni.getStorageSync('bindAgentId')) bindAgentId()
                                uni.switchTab({
                                    url: "/pages/index/index",
                                })
                            }
                        });
                    },
                    fail(res) {
                        console.log(res, "登录失败");
                    },
                });
        }
    },
};
</script>

<style lang="scss" scoped>
.content_box {
    position: relative;
    .bg {
        background: #54B62D;
        height: 30vh;
        border-bottom-right-radius: 118rpx;
    }

    .content {
        position: absolute;
        top: 0;
        left: 50%;
        transform: translateX(-50%);
    }
}

</style>
